﻿<html>
<head>
    <script type="text/javascript">
        function setSWFIsReady(movieName)
        {
            //alert(movieName);
        }
        function getSwf(src)
        {
            var swfTemplate = '    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
                    'codebase="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"'+
                    'WIDTH="100%" HEIGHT="100%" id="myMovieName">'+
                    '        <PARAM NAME="movie" VALUE="' + src +'">'+
                    '        <PARAM NAME="quality" VALUE="high">'+
                    '        <PARAM NAME="bgcolor" VALUE="#FFFFFF">'+
                    '        <PARAM NAME="play" VALUE="true">'+
                    '        <PARAM NAME="loop" VALUE="true">'+
                    '        <PARAM NAME=bgcolor VALUE="#FFFFFF">'+
                    '        <PARAM NAME=FlashVars VALUE="g1=obaidan">'+
                    '        <PARAM NAME=FlashVars VALUE="g2=11111">'+
                    '        <EMBED src="' + src +'" quality=high bgcolor=#FFFFFF WIDTH="100%" HEIGHT="100%"'+
                    '           FlashVars="g1=obaidan"' +
                    '           FlashVars="g2=11111"' +
                    'NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash"'+
                    'play="true" loop="true"'+
                    'PLUGINSPAGE="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'+
                    '        </EMBED>'+
                    '        </OBJECT>';
            return swfTemplate;
        }

        function setValue(pValue, dValue)
        {
            getMovie('myMovieName').setDataSource('plant', pValue);
            getMovie('myMovieName').setDataSource('org', dValue);
        }


        function getMovie(movieName) {
            var movie = undefined;
            if (navigator.appName.indexOf("Microsoft") != -1) {
                movie = document.getElementById(movieName);
            } else {
                movie = document[movieName];
            }
            return movie;
        }


        function getParameter(paramName)
        {
            var searchString = window.location.search.substring(1),
                    i, val, params = searchString.split("&");

            for (i=0;i<params.length;i++)
            {
                val = params[i].split("=");
                if (val[0] == paramName)
                {
                    return unescape(val[1]);
                }
            }
            return null;
        }
        function createFlashMarkup(width,height,uri,replaceid)
        {
            var embed = document.createElement('embed');
            embed.setAttribute('id', 'myMovieName');
            embed.setAttribute('width',width);
            embed.setAttribute('height',height);
            embed.setAttribute('src',uri);

            var div = document.getElementById(replaceid);
            document.getElementsByTagName('body')[0].replaceChild(embed,div);
        }
        var refreshInterval;
        function create()
        {
            document.getElementById('kpi-container').innerHTML = getSwf(getParameter('kpi'));
            refreshInterval=setInterval(detectLoading,100);
        }
        function refresh()
        {
            var plant = window.top.getPlantFromChild().split(":");
            setValue(plant[0], 'division');
        }

        function refresh2()
        {
            var p = document.getElementById('plant').value;
            var o = document.getElementById('org').value;
            setValue(p, o);
        }







        var doneReading=false;
        function detectLoading()
        {
            try
            {
                var doneDetection=getMovie("myMovieName").getDataSource("p1");
                if(doneDetection)
                {
                    doneReading=true;
                }
            }
            catch (error){}
            if(doneReading==true)
            {
                clearInterval(refreshInterval);
                //do your stuff now
                refresh();
            }
        }



    </script>

    <style type="text/css">
        #kpi-container {
            width: 100%; height: 100%;
            padding: 0 0 0 0;
        }
    </style>
</head>

<body onload="create();">
    Plant: <input type="text" id="plant" />
    Org: <input type="text" id="org" />
    <input type="button" value="Update" onclick="refresh2()"/>
    <div id="kpi-container">

    </div>
</body>
</html>